//
//  UIButton+Dzm.m
//  duzhoumo
//
//  Created by 度周末网络-王腾 on 15/11/10.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "UIButton+Dzm.h"
#import <objc/runtime.h>

static const void *UIButtonBlockKey = &UIButtonBlockKey;

@implementation UIButton (Dzm)

-(void)addActionHandler:(TouchedBlock)touchHandler{
    objc_setAssociatedObject(self, UIButtonBlockKey, touchHandler, OBJC_ASSOCIATION_COPY_NONATOMIC);
    [self addTarget:self action:@selector(actionTouched:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)actionTouched:(UIButton *)btn{
    TouchedBlock block = objc_getAssociatedObject(self, UIButtonBlockKey);
    if (block) {
        block(btn);
    }
}

-(void)setRadius:(CGFloat)cordius{
    self.layer.cornerRadius = cordius;
    self.layer.masksToBounds= YES;
    self.backgroundColor= GLOBLE_ORANGE_COLOR;
}

-(void)styleButton{
    self.layer.cornerRadius = 5;
    self.backgroundColor =  GLOBLE_ORANGE_COLOR;
    self.layer.masksToBounds=YES;
    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.titleLabel.font = [UIFont systemFontOfSize:15];
}


-(void)style1Button{
    self.layer.cornerRadius = 6;
    self.backgroundColor =  [UIColor whiteColor];
    self.layer.masksToBounds=YES;
    [self setTitleColor:GLOBLE_ORANGE_COLOR forState:UIControlStateNormal];
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    self.layer.borderColor = GLOBLE_ORANGE_COLOR.CGColor;
    self.layer.borderWidth = 0.45;
}
@end
